#include <vector>
#include <iostream>

using namespace std;

class Solution 
{
public:
    int uniquePathsWithObstacles(vector<vector<int> > & grids) 
	{
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		size_t m = grids.size();
		if(m==0)
			return 0;

		size_t n = grids[0].size();
		if(n==0)
			return 0;

		vector<vector<int> > paths(m);
		for(size_t i=0;i<m;i++)
			paths[i] = vector<int>(n,0);

		paths[m-1][n-1] = grids[m-1][n-1]?0:1;

		for(size_t i=n-2;i!=-1;i--)
			paths[m-1][i] = grids[m-1][i]?0:paths[m-1][i+1];
		for(size_t i=m-2;i!=-1;i--)
			paths[i][n-1] = grids[i][n-1]?0:paths[i+1][n-1];


		for(size_t i=m-2;i!=-1;i--)
			for(size_t j=n-2;j!=-1;j--)
				paths[i][j] = grids[i][j]?0:(paths[i][j+1] + paths[i+1][j]);

		return paths[0][0];
    }
};

int main()
{
	Solution s;
	int m,n;
	while(cin>>m)
	{
		if(m<=0)
			break;
		cin>>n;
		vector<vector<int> > grids(m);
		for(int i=0;i<m;i++)
		{
			grids[i] = vector<int>(n);
			for(int j=0;j<n;j++)
				cin>>grids[i][j];
		}
			
		cout<<s.uniquePathsWithObstacles(grids)<<endl;
	}
}